/**
 * 
 */
package idv.takeshi.software.productline.bookstore.application.service;

import idv.takeshi.software.productline.bookstore.domain.model.valueobject.InternationalText;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author takeshi
 *
 */
public class BeansInitializer implements BeanPostProcessor {

	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
	 */
	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		if(StringUtils.isBlank(InternationalText.getDefaultLocale())){
			InternationalText.addNeededLocale(Constants.US_LOCALE);
			InternationalText.addNeededLocale(Constants.TW_LOCALE);
			InternationalText.setDefaultLocale(Constants.US_LOCALE);
		}
		return bean;
	}

	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
	 */
	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		//DO NOTHING
		return bean;
	}

}
